/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.namabank.util;

/**
 *
 * @author Admin
 */
public final class ClientInfo {

    public static final String FIREFOX = "Firefox";
    public static final String MSIE = "MSIE";
    public static final String CHROME = "Chrome";
    public static final String OPERA = "Opera";
    public static final String SAFARI = "Safari";

    public ClientInfo() {
    }

    public ClientInfo(String userAgent) {
        setUserAgent(userAgent);
    }
    public ClientInfo(String userAgent, String ip) {
        setUserAgent(userAgent);
        IP = ip;
    }
    private String IP;
    private String browserName;
    private String browserVersion;
    private String OS;
    private String userAgent;

    public Boolean isFirefox() {
        if (FIREFOX.equals(browserName)) {
            return true;
        }
        return false;
    }

    public Boolean isMSIE() {
        if (MSIE.equals(browserName)) {
            return true;
        }
        return false;
    }

    public Boolean isChrome() {
        if (CHROME.equals(browserName)) {
            return true;
        }
        return false;
    }

    public Boolean isSafari() {
        if (SAFARI.equals(browserName)) {
            return true;
        }
        return false;
    }

    public Boolean isOpera() {
        if (OPERA.equals(browserName)) {
            return true;
        }
        return false;
    }

    /**
     * @return the IP
     */
    public String getIP() {
        return IP;
    }

    /**
     * @param IP the IP to set
     */
    public void setIP(String IP) {
        this.IP = IP;
    }

    /**
     * @return the browserName
     */
    public String getBrowserName() {
        return browserName;
    }

    /**
     * @param browserName the browserName to set
     */
    public void setBrowserName(String browserName) {
        this.browserName = browserName;
    }

    /**
     * @return the browserVersion
     */
    public String getBrowserVersion() {
        return browserVersion;
    }

    /**
     * @param browserVersion the browserVersion to set
     */
    public void setBrowserVersion(String browserVersion) {
        this.browserVersion = browserVersion;
    }

    /**
     * @return the OS
     */
    public String getOS() {
        return OS;
    }

    /**
     * @param OS the OS to set
     */
    public void setOS(String OS) {
        this.OS = OS;
    }

    /**
     * @return the userAgent
     */
    public String getUserAgent() {
        return userAgent;
    }

    /**
     * @param userAgent the userAgent to set
     */
    public void setUserAgent(String userAgent) {
        this.userAgent = userAgent;

        if (userAgent != null && userAgent.length() > 0) {
            String pattern = " Firefox/";
            int ind01 = userAgent.indexOf(pattern);
            if (ind01 >= 0) {
                browserName = FIREFOX;
                int ind02 = userAgent.indexOf(";", ind01);
                browserVersion = userAgent.substring(ind01 + pattern.length(), (ind02 < 0? userAgent.length(): ind02));
            }
            if(ind01 < 0) {
                pattern = " MSIE ";
                ind01 = userAgent.indexOf(pattern);
                if (ind01 > 0) {
                    browserName = MSIE;
                    int ind02 = userAgent.indexOf(";", ind01);
                    browserVersion = userAgent.substring(ind01 + pattern.length(), (ind02 < 0? userAgent.length(): ind02));
                }
            }
            if(ind01 < 0) {
                pattern = " Chrome/";
                ind01 = userAgent.indexOf(pattern);
                if (ind01 > 0) {
                    browserName = CHROME;
                    int ind02 = userAgent.indexOf(" ", ind01);
                    browserVersion = userAgent.substring(ind01 + pattern.length(), (ind02 < 0? userAgent.length(): ind02));
                }
            }
            if(userAgent.indexOf("Windows NT 5.1") > 0){
                OS = "Windows XP";
            }else if(userAgent.indexOf("Windows") > 0){
                OS = "Windows";
            }
        }
    }
}
